package com.example.flowermall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.flowermall.entity.ProductImg;
import com.example.flowermall.mapper.ProductImgMapper;
import com.example.flowermall.service.IProductImgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaoman
 * @since 2023-09-26
 */
@Service
public class ProductImgServiceImpl extends ServiceImpl<ProductImgMapper, ProductImg> implements IProductImgService {

    @Autowired
    ProductImgMapper productImgMapper;
    @Override
    public ProductImg getByProductId(Integer id) {
        LambdaQueryWrapper<ProductImg> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductImg::getProductId,id);
        queryWrapper.eq(ProductImg::getMainImg,1);
        queryWrapper.eq(ProductImg::getIsIntegral,0);
        return productImgMapper.selectOne(queryWrapper);
    }

    @Override
    public List<ProductImg> getListByProductId(Integer id) {
        LambdaQueryWrapper<ProductImg> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductImg::getProductId,id);
        queryWrapper.eq(ProductImg::getIsIntegral,0);
        return productImgMapper.selectList(queryWrapper);
    }

    @Override
    public void add(ProductImg productImg) {
        productImgMapper.insert(productImg);
    }

    @Override
    public void deleteByProductId(Integer productId) {
        LambdaQueryWrapper<ProductImg> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductImg::getProductId,productId);
        queryWrapper.eq(ProductImg::getIsIntegral,0);
        productImgMapper.delete(queryWrapper);
    }

    @Override
    public List<ProductImg> getListByIntegralProductId(Integer productId) {
        LambdaQueryWrapper<ProductImg> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductImg::getProductId,productId);
        queryWrapper.eq(ProductImg::getIsIntegral,1);
        return productImgMapper.selectList(queryWrapper);
    }

    @Override
    public ProductImg getByIntegralProductId(Integer productId) {
        LambdaQueryWrapper<ProductImg> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductImg::getProductId,productId);
        queryWrapper.eq(ProductImg::getMainImg,1);
        queryWrapper.eq(ProductImg::getIsIntegral,1);
        return productImgMapper.selectOne(queryWrapper);
    }

    @Override
    public void deleteByIntegralProductId(Integer productId) {
        LambdaQueryWrapper<ProductImg> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductImg::getProductId,productId);
        queryWrapper.eq(ProductImg::getIsIntegral,1);
        productImgMapper.delete(queryWrapper);
    }
}
